package com.factorit.business;

import java.io.File;

import org.joone.engine.Layer;
import org.joone.engine.learning.TeachingSynapse;
import org.joone.io.FileInputSynapse;

import com.factorit.beans.NeuronalNet;

/**
 * Entrenador de la red neuronal
 * @author Mural
 *
 */
public class Trainer extends TeachingSynapse {
	

	private static final long serialVersionUID = 2150142480437808868L;

	public void train(NeuronalNet redNeuronal) {
		
		Layer input = redNeuronal.getInputLayer();
		Layer output = redNeuronal.getOutputLayer();
		
		FileInputSynapse inputStream = new FileInputSynapse();
		/* The first two columns contain the input values */
		inputStream.setAdvancedColumnSelector("1,2");
		/* This is the file that contains the input data */
		inputStream.setInputFile(new File("c:\\XOR.txt"));
		input.addInputSynapse(inputStream);
		
		/* Setting of the file containing the desired responses, provided by a FileInputSynapse */
		FileInputSynapse samples = new FileInputSynapse();
		samples.setInputFile(new File("c:\\XOR.txt"));
		this.setDesired(samples);
		/* The output values are on the third column of the file */
		samples.setAdvancedColumnSelector("3");
		/* We add it to the neural network */
		redNeuronal.setTeacher(this);
		
		output.addOutputSynapse(this);

	}

}
